package com.yeu.action;

import java.util.HashMap;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.yeu.model.Event;
import com.yeu.util.MailTool;

public class MailAction extends ActionSupport implements ModelDriven<Event>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Event event=new Event();
	private Map<String, Boolean> boolResult;

	public Map<String, Boolean> getBoolResult() {
		return boolResult;
	}

	@Override
	public Event getModel() {
		return this.event;
	}

	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	@Override
	public String execute() throws Exception {
		boolResult=new HashMap<String, Boolean>();
		String subject=event.getEventType()+" "+event.getEventDate();
		String to=event.getReporterMail();
		String content=makeMailContent();
		if(MailTool.sendAndCc(to, "", subject, content)){
			boolResult.put("RESULT", true);
		}
		else{
			boolResult.put("RESULT", false);
		}
		return "boolResult";
	}
	
	private String makeMailContent(){
		StringBuilder mailContent=new StringBuilder();
		mailContent.append("报案人姓名:"+event.getReporterName()+"\r\n<br/>");
		mailContent.append("报案人学号:"+event.getReporterId()+"\r\n<br/>");
		mailContent.append("报案人班级:"+event.getReporterClass()+"\r\n<br/>");
		mailContent.append("报案人手机:"+event.getReporterPhoneNum()+"\r\n<br/>");
		mailContent.append("报案人邮箱:"+event.getReporterMail()+"\r\n<br/>");
		mailContent.append("报案人班主任:"+event.getReporterMonitorName()+"\r\n<br/>");
		mailContent.append("报案人辅导员:"+event.getReporterDirectorName()+"\r\n<br/>");
		mailContent.append("事件号:"+event.getEventId()+"\r\n<br/>");
		mailContent.append("事件类型:"+event.getEventType()+"\r\n<br/>");
		mailContent.append("事件日期:"+event.getEventDate()+"\r\n<br/>");
		mailContent.append("事件主管:"+event.getEventAdminByName()+"\r\n<br/>");
		mailContent.append("事件内容:"+event.getEventContent()+"\r\n<br/>");
		return mailContent.toString();
	}
}
